{% extends "main/base.html" %}
{% load i18n main_tag %}
{% block title %}{% trans '订单详情' %}{% endblock %}
{% block content %}
<div class="panel">
    <header class="panel-heading">
        {% trans "订单详情" %}  {{ object.order_state }}
    </header>
    <div class="panel-body">
        <div class="object-group col-md-12 text-right">{% if perms.main.view_equipment_basic_price %}
            <a href="/main/order_quotation/{{ object.order_key }}/{{ object.id|escape }}/?v=page" target="_blank"><button type="button" class="btn btn-xs btn-danger">{% trans '中文报价单' %}</button></a>
            <a href="{% url 'main:order_contract_cn' object.id|escape %}?v=page" target="_blank"><button type="button" class="btn btn-xs btn-info">{% trans '中文合同' %}</button></a>
<!--            <a href="/main/order_quotation/{{ object.order_key }}/{{ object.id|escape }}/?v=page" target="_blank"><button type="button" class="btn btn-xs btn-danger">{% trans '英文报价单-Old' %}</button></a>-->
<!--            <a href="/main/order_quotation_en/{{ object.order_key }}/{{ object.id|escape }}/?v=page" target="_blank"><button type="button" class="btn btn-xs btn-danger">{% trans '英文报价单-New' %}</button></a>-->
<!--            <a href="{% url 'main:order_invoice_en' object.id|escape %}?v=pdf" target="_blank"><button type="button" class="btn btn-xs btn-info">{% trans '英文发票' %}</button></a>-->
<!--            <a href="{% url 'main:order_contract_en' object.id|escape %}?v=pdf" target="_blank"><button type="button" class="btn btn-xs btn-info">{% trans '英文合同' %}</button></a>-->
            {% endif %}
            <a href="{% url 'main:order_production_list' object.order_key object.id|escape %}?v=page" target="_blank"><button type="button" class="btn btn-xs btn-info">{% trans '工程单' %}</button></a>
            {% if not object.order_state.is_confirmed %}
                <a class="btn btn-xs btn-success" data-toggle="modal" href="#myModal">{% trans '成功下单' %}</a>
                <div class="modal fade text-left" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                                  <div class="modal-dialog">
                                      <div class="modal-content">
                                          <div class="modal-header">
                                              <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                              <h4 class="modal-title">确认成功下单</h4>
                                          </div>
                                          <div class="modal-body">
                                              该订单将被锁定，并短信通知相关人员！
                                              <br>
                                              请及时上传签字盖章的合同扫描件。
                                          </div>
                                          <div class="modal-footer">
                                              <button data-dismiss="modal" class="btn btn-default" type="button">{% trans '关闭' %}</button>
                                              <a href="{% url 'main:order_confirm' object.id|escape %}"><button class="btn btn-success" type="button">{% trans '确认' %}</button></a>
                                          </div>
                                      </div>
                                  </div>
                              </div>
            {% endif %}
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "创建日期" %}</div>
            <div class="col-sm-9">{{ object.order_create_date }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "有效日期" %}</div>
            <div class="col-sm-9">{{ object.order_validity_date }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "订单编号" %}</div>
            <div class="col-sm-9">{{ object.order_code }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "订单描述" %}</div>
            <div class="col-sm-9">{{ object.order_desc }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "客户" %}</div>
            <div class="col-sm-9">{{ object.client }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "销售员" %}</div>
            <div class="col-sm-9">{{ object.salesman }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "生产周期" %}</div>
            <div class="col-sm-9">{{ object.manufacturing_days }} {% trans "天" %}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "成功率" %}</div>
            <div class="col-sm-9">{{ object.success_rate }} %</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "对接公司" %}</div>
            <div class="col-sm-9">{{ object.sub_company }}</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "运输方式" %}</div>
            <div class="col-sm-9">{{ object.transport_type }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "付款方式" %}</div>
            <div class="col-sm-10">{{ object.order_pay_method }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "收款帐号" %}</div>
            <div class="col-sm-10">{{ object.bank_account }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "安装说明" %}</div>
            <div class="col-sm-10">{{ object.installation_desc }}{{ object.installation_desc.errors }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "工程材料" %}</div>
            <div class="col-sm-10">{{ object.Installation_materials }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "附属条款" %}</div>
            <div class="col-sm-10">{{ object.order_notes }}</div>
        </div>{% if perms.main.view_equipment_basic_price %}
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "运输费用" %}</div>
            <div class="col-sm-9">{{ object.transport_cost }} 元</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "安装费用" %}</div>
            <div class="col-sm-9">{{ object.install_cost }} 元</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "工程材料" %}</div>
            <div class="col-sm-9">{{ object.material_cost }} 元</div>
        </div>
        <div class="object-group col-md-6">
            <div class="col-sm-3">{% trans "税率" %}</div>
            <div class="col-sm-9">{{ object.tax_rate }} %</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "订单总价" %}</div>
            <div class="col-sm-10">
                {{ object.total_price }} - {{ object.total_discount }} + {{ object.price_tax }} = {{ object.price_with_tax }} 元
                </div>
        </div>{% endif %}
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "订单备注" %}</div>
            <div class="col-sm-10">{{ object.app_notes|linebreaks }}</div>
        </div>
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "总功率" %}</div>
            <div class="col-sm-10">{{ object.total_power }} kw</div>
        </div>{% if perms.main.view_contract %}
        <div class="object-group col-md-9">
            <div class="col-sm-2">{% trans "报价单/合同" %}</div>
            <div class="col-sm-10">
            {% if object.order_file %}报价单：<a href="{{ object.order_file|qiniu }}" target="_blank">{{ object.order_file.name|short }}</a><br>{% endif %}
            {% if object.order_file_c %}合同：<a href="{{ object.order_file_c|qiniu }}" target="_blank">{{ object.order_file_c.name|short }}</a>{% endif %}
            </div>
        </div>{% endif %}
        <div class="object-group col-md-12 text-right">{% if perms.main.view_contract %}
            <a href="{% url 'main:order_file_update' object.pk %}"><button type="button" class="btn btn-danger">{% trans "文件上传" %}</button></a>{% endif %}
            {% if object.order_state.can_edit == True %}{% if perms.main.change_order and object.created_by_id == request.user.pk %}
            <a href="{% url 'main:order_editor_update' object.pk %}"><button type="button" class="btn btn-success">{% trans "参与者编辑" %}</button></a>{% endif %}{% if perms.main.change_order %}
            <a href="{% url 'main:order_update' object.pk %}"><button type="button" class="btn btn-info">{% trans "订单编辑" %}</button></a>{% endif %}{% if perms.main.add_itemlist %}
            <a href="{% url 'main:batch_add_order_items' object.pk %}"><button type="button" class="btn btn-success">{% trans "批量添加设备" %}</button></a>
            <a href="{% url 'main:order_add_item' object.pk %}"><button type="button" class="btn btn-danger">{% trans "添加设备" %}</button></a>{% endif %}{% endif %}
        </div>
    </div>
    <div class="table-responsive panel-body widget-shadow">
        <table class="table">
            <thead>
            <tr>
                <th>{% trans "排序" %}</th>
                <th>{% trans "设备编号" %}</th>
                <th>{% trans "英文名" %}</th>
                <th>{% trans "中文名" %}</th>
                <th>{% trans "设备类型" %}</th>
                <th>{% trans "数量" %}</th>{% if perms.main.view_equipment_basic_price %}
                <th>{% trans "原价" %}</th>
                <th>{% trans "单价" %}</th>
                <th>{% trans "小计" %}</th>{% endif %}
                <th></th>
            </tr>
            </thead>
            <tbody>
            {% for item in order_items %}
            <tr>
                <td>{{ item.order_index }}</td>
                <td><a href="{% url 'main:equipment_detail' item.equipment.id %}" target="_blank">{{ item.equipment.equipment_code }}</a></td>
                <td>{{ item.equipment.equipment_en }}</td>
                <td>{{ item.equipment.equipment_cn }}</td>
                <td>{{ item.equipment.equipment_type.equipment_type_cn }}</td>
                <td>{{ item.amount }}</td>{% if perms.main.view_equipment_basic_price %}
                <td>{{ item.item_basic_price_auto }} {{ item.order.price_unit }}</td>
                <td>{{ item.item_price_each_auto }} {{ item.order.price_unit }}</td>
                <td>{{ item.item_final_price_auto }} {{ item.order.price_unit }}</td>{% endif %}
                <td class="text-right">
                    {% if perms.main.change_itemlist %}{% if not object.order_state_id == 2 %}<a href="{% url 'main:order_item_update' item.id %}"><button class="btn btn-danger btn-xs"><i class="fa fa-pencil"></i></button></a>{% endif %}{% endif %}
                    {% if perms.main.change_production_list %}{% if object.order_state_id == 2 %}<a href="{% url 'main:item_note_update' item.pk %}"><button class="btn btn-success btn-xs"><i class="fa fa-pencil"></i></button></a>{% endif %}{% endif %}</td>
            </tr>
            {% endfor %}
            </tbody>
        </table>
    </div>
</div>
{% endblock %}